home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / PRNMNGR.VB_ / prnmngr.vbs
Encoding:
Text File  |  2003-02-21  |  42.8 KB  |  1,426 lines

  1. '----------------------------------------------------------------------
  2. '
  3. ' Copyright (c) Microsoft Corporation. All rights reserved.
  4. '
  5. ' Abstract:
  6. ' prnmngr.vbs - printer script for WMI on Whistler
  7. '     used to add, delete, and list printers and connections
  8. '     also for getting and setting the default printer
  9. '
  10. ' Usage:
  11. ' prnmngr [-adxgtl?][co] [-s server][-p printer][-m driver model][-r port]
  12. '                       [-u user name][-w password]
  13. '
  14. ' Examples:
  15. ' prnmngr -a -p "printer" -m "driver" -r "lpt1:" 
  16. ' prnmngr -d -p "printer" -s server
  17. ' prnmngr -ac -p "\\server\printer"
  18. ' prnmngr -d -p "\\server\printer"
  19. ' prnmngr -x -s server
  20. ' prnmngr -l -s server
  21. ' prnmngr -g
  22. ' prnmngr -t -p "printer"
  23. '
  24. '----------------------------------------------------------------------
  25.  
  26. option explicit
  27.  
  28. '
  29. ' Debugging trace flags, to enable debug output trace message
  30. ' change gDebugFlag to true.
  31. '
  32. const kDebugTrace = 1
  33. const kDebugError = 2
  34. dim   gDebugFlag
  35.  
  36. gDebugFlag = false
  37.  
  38. '
  39. ' Operation action values.
  40. '
  41. const kActionUnknown           = 0
  42. const kActionAdd               = 1
  43. const kActionAddConn           = 2
  44. const kActionDel               = 3
  45. const kActionDelAll            = 4
  46. const kActionDelAllCon         = 5
  47. const kActionDelAllLocal       = 6
  48. const kActionList              = 7
  49. const kActionGetDefaultPrinter = 8
  50. const kActionSetDefaultPrinter = 9
  51.  
  52. const kErrorSuccess            = 0
  53. const KErrorFailure            = 1
  54.  
  55. const kFlagCreateOnly          = 2
  56.  
  57. const kNameSpace               = "root\cimv2"
  58.  
  59. '
  60. ' Generic strings
  61. '
  62. const L_Empty_Text                 = ""
  63. const L_Space_Text                 = " "
  64. const L_Error_Text                 = "Error"
  65. const L_Success_Text               = "Success"
  66. const L_Failed_Text                = "Failed"
  67. const L_Hex_Text                   = "0x"
  68. const L_Printer_Text               = "Printer"
  69. const L_Operation_Text             = "Operation"
  70. const L_Provider_Text              = "Provider"
  71. const L_Description_Text           = "Description"
  72. const L_Debug_Text                 = "Debug:"
  73. const L_Connection_Text            = "connection"
  74.  
  75. '
  76. ' General usage messages
  77. '                                 
  78. const L_Help_Help_General01_Text   = "Usage: prnmngr [-adxgtl?][c] [-s server][-p printer][-m driver model]"
  79. const L_Help_Help_General02_Text   = "               [-r port][-u user name][-w password]" 
  80. const L_Help_Help_General03_Text   = "Arguments:"
  81. const L_Help_Help_General04_Text   = "-a     - add local printer"
  82. const L_Help_Help_General05_Text   = "-ac    - add printer connection"
  83. const L_Help_Help_General06_Text   = "-d     - delete printer"
  84. const L_Help_Help_General07_Text   = "-g     - get the default printer"
  85. const L_Help_Help_General08_Text   = "-l     - list printers"
  86. const L_Help_Help_General09_Text   = "-m     - driver model"
  87. const L_Help_Help_General10_Text   = "-p     - printer name"
  88. const L_Help_Help_General11_Text   = "-r     - port name"
  89. const L_Help_Help_General12_Text   = "-s     - server name"
  90. const L_Help_Help_General13_Text   = "-t     - set the default printer"
  91. const L_Help_Help_General14_Text   = "-u     - user name"
  92. const L_Help_Help_General15_Text   = "-w     - password"
  93. const L_Help_Help_General16_Text   = "-x     - delete all printers"
  94. const L_Help_Help_General17_Text   = "-xc    - delete all printer connections"
  95. const L_Help_Help_General18_Text   = "-xo    - delete all local printers"
  96. const L_Help_Help_General19_Text   = "-?     - display command usage"
  97. const L_Help_Help_General20_Text   = "Examples:"
  98. const L_Help_Help_General21_Text   = "prnmngr -a -p ""printer"" -m ""driver"" -r ""lpt1:"""
  99. const L_Help_Help_General22_Text   = "prnmngr -d -p ""printer"" -s server"
  100. const L_Help_Help_General23_Text   = "prnmngr -ac -p ""\\server\printer"""
  101. const L_Help_Help_General24_Text   = "prnmngr -d -p ""\\server\printer"""
  102. const L_Help_Help_General25_Text   = "prnmngr -x -s server"
  103. const L_Help_Help_General26_Text   = "prnmngr -xo"
  104. const L_Help_Help_General27_Text   = "prnmngr -l -s server"
  105. const L_Help_Help_General28_Text   = "prnmngr -g"
  106. const L_Help_Help_General29_Text   = "prnmngr -t -p ""\\server\printer"""
  107.  
  108. '
  109. ' Messages to be displayed if the scripting host is not cscript
  110. '                            
  111. const L_Help_Help_Host01_Text      = "Please run this script using CScript."  
  112. const L_Help_Help_Host02_Text      = "This can be achieved by"
  113. const L_Help_Help_Host03_Text      = "1. Using ""CScript script.vbs arguments"" or" 
  114. const L_Help_Help_Host04_Text      = "2. Changing the default Windows Scripting Host to CScript"
  115. const L_Help_Help_Host05_Text      = "   using ""CScript //H:CScript //S"" and running the script "
  116. const L_Help_Help_Host06_Text      = "   ""script.vbs arguments""."
  117.  
  118. '
  119. ' General error messages
  120. '                                                 
  121. const L_Text_Error_General01_Text  = "The scripting host could not be determined."                
  122. const L_Text_Error_General02_Text  = "Unable to parse command line." 
  123. const L_Text_Error_General03_Text  = "Win32 error code"
  124.  
  125. '
  126. ' Miscellaneous messages
  127. '
  128. const L_Text_Msg_General01_Text    = "Added printer"
  129. const L_Text_Msg_General02_Text    = "Unable to add printer"
  130. const L_Text_Msg_General03_Text    = "Added printer connection"
  131. const L_Text_Msg_General04_Text    = "Unable to add printer connection"
  132. const L_Text_Msg_General05_Text    = "Deleted printer"
  133. const L_Text_Msg_General06_Text    = "Unable to delete printer"
  134. const L_Text_Msg_General07_Text    = "Attempting to delete printer"
  135. const L_Text_Msg_General08_Text    = "Unable to delete printers"
  136. const L_Text_Msg_General09_Text    = "Number of local printers and connections enumerated"
  137. const L_Text_Msg_General10_Text    = "Number of local printers and connections deleted"    
  138. const L_Text_Msg_General11_Text    = "Unable to enumerate printers"
  139. const L_Text_Msg_General12_Text    = "The default printer is"
  140. const L_Text_Msg_General13_Text    = "Unable to get the default printer"
  141. const L_Text_Msg_General14_Text    = "Unable to set the default printer"
  142. const L_Text_Msg_General15_Text    = "The default printer is now"
  143. const L_Text_Msg_General16_Text    = "Number of printer connections enumerated"
  144. const L_Text_Msg_General17_Text    = "Number of printer connections deleted"    
  145. const L_Text_Msg_General18_Text    = "Number of local printers enumerated"
  146. const L_Text_Msg_General19_Text    = "Number of local printers deleted"    
  147.  
  148. '
  149. ' Printer properties
  150. '
  151. const L_Text_Msg_Printer01_Text    = "Server name"
  152. const L_Text_Msg_Printer02_Text    = "Printer name"
  153. const L_Text_Msg_Printer03_Text    = "Share name"
  154. const L_Text_Msg_Printer04_Text    = "Driver name"
  155. const L_Text_Msg_Printer05_Text    = "Port name"
  156. const L_Text_Msg_Printer06_Text    = "Comment"
  157. const L_Text_Msg_Printer07_Text    = "Location"
  158. const L_Text_Msg_Printer08_Text    = "Separator file"
  159. const L_Text_Msg_Printer09_Text    = "Print processor"
  160. const L_Text_Msg_Printer10_Text    = "Data type"
  161. const L_Text_Msg_Printer11_Text    = "Parameters"
  162. const L_Text_Msg_Printer12_Text    = "Attributes"
  163. const L_Text_Msg_Printer13_Text    = "Priority"
  164. const L_Text_Msg_Printer14_Text    = "Default priority"
  165. const L_Text_Msg_Printer15_Text    = "Start time"
  166. const L_Text_Msg_Printer16_Text    = "Until time"
  167. const L_Text_Msg_Printer17_Text    = "Job count"
  168. const L_Text_Msg_Printer18_Text    = "Average pages per minute"
  169. const L_Text_Msg_Printer19_Text    = "Printer status"
  170. const L_Text_Msg_Printer20_Text    = "Extended printer status"
  171. const L_Text_Msg_Printer21_Text    = "Detected error state"
  172. const L_Text_Msg_Printer22_Text    = "Extended detected error state"
  173.  
  174.  
  175. '
  176. ' Printer status
  177. '
  178. const L_Text_Msg_Status01_Text     = "Other"
  179. const L_Text_Msg_Status02_Text     = "Unknown"
  180. const L_Text_Msg_Status03_Text     = "Idle"
  181. const L_Text_Msg_Status04_Text     = "Printing"
  182. const L_Text_Msg_Status05_Text     = "Warmup"
  183. const L_Text_Msg_Status06_Text     = "Stopped printing"
  184. const L_Text_Msg_Status07_Text     = "Offline"
  185. const L_Text_Msg_Status08_Text     = "Paused"
  186. const L_Text_Msg_Status09_Text     = "Error"
  187. const L_Text_Msg_Status10_Text     = "Busy"
  188. const L_Text_Msg_Status11_Text     = "Not available"
  189. const L_Text_Msg_Status12_Text     = "Waiting"
  190. const L_Text_Msg_Status13_Text     = "Processing"
  191. const L_Text_Msg_Status14_Text     = "Initializing"
  192. const L_Text_Msg_Status15_Text     = "Power save"
  193. const L_Text_Msg_Status16_Text     = "Pending deletion"
  194. const L_Text_Msg_Status17_Text     = "I/O active"
  195. const L_Text_Msg_Status18_Text     = "Manual feed"
  196. const L_Text_Msg_Status19_Text     = "No error"
  197. const L_Text_Msg_Status20_Text     = "Low paper"
  198. const L_Text_Msg_Status21_Text     = "No paper"
  199. const L_Text_Msg_Status22_Text     = "Low toner"
  200. const L_Text_Msg_Status23_Text     = "No toner"
  201. const L_Text_Msg_Status24_Text     = "Door open"
  202. const L_Text_Msg_Status25_Text     = "Jammed"
  203. const L_Text_Msg_Status26_Text     = "Service requested"
  204. const L_Text_Msg_Status27_Text     = "Output bin full"
  205. const L_Text_Msg_Status28_Text     = "Paper problem"
  206. const L_Text_Msg_Status29_Text     = "Cannot print page"
  207. const L_Text_Msg_Status30_Text     = "User intervention required"
  208. const L_Text_Msg_Status31_Text     = "Out of memory"
  209. const L_Text_Msg_Status32_Text     = "Server unknown"
  210.  
  211. '
  212. ' Debug messages
  213. '
  214. const L_Text_Dbg_Msg01_Text        = "In function AddPrinter"
  215. const L_Text_Dbg_Msg02_Text        = "In function AddPrinterConnection"
  216. const L_Text_Dbg_Msg03_Text        = "In function DelPrinter"
  217. const L_Text_Dbg_Msg04_Text        = "In function DelAllPrinters"
  218. const L_Text_Dbg_Msg05_Text        = "In function ListPrinters"
  219. const L_Text_Dbg_Msg06_Text        = "In function GetDefaultPrinter"
  220. const L_Text_Dbg_Msg07_Text        = "In function SetDefaultPrinter"
  221. const L_Text_Dbg_Msg08_Text        = "In function ParseCommandLine"
  222.  
  223. main
  224.  
  225. '
  226. ' Main execution starts here
  227. '
  228. sub main
  229.  
  230.     dim iAction
  231.     dim iRetval
  232.     dim strServer
  233.     dim strPrinter
  234.     dim strDriver
  235.     dim strPort
  236.     dim strUser
  237.     dim strPassword
  238.     
  239.     '
  240.     ' Abort if the host is not cscript
  241.     '
  242.     if not IsHostCscript() then
  243.    
  244.         call wscript.echo(L_Help_Help_Host01_Text & vbCRLF & L_Help_Help_Host02_Text & vbCRLF & _
  245.                           L_Help_Help_Host03_Text & vbCRLF & L_Help_Help_Host04_Text & vbCRLF & _
  246.                           L_Help_Help_Host05_Text & vbCRLF & L_Help_Help_Host06_Text & vbCRLF)
  247.         
  248.         wscript.quit
  249.    
  250.     end if
  251.  
  252.     '
  253.     ' Get command line parameters
  254.     '
  255.     iRetval = ParseCommandLine(iAction, strServer, strPrinter, strDriver, strPort, strUser, strPassword)
  256.  
  257.     if iRetval = kErrorSuccess then
  258.  
  259.         select case iAction
  260.  
  261.             case kActionAdd
  262.                  iRetval = AddPrinter(strServer, strPrinter, strDriver, strPort, strUser, strPassword)
  263.  
  264.             case kActionAddConn
  265.                  iRetval = AddPrinterConnection(strPrinter, strUser, strPassword)
  266.               
  267.             case kActionDel
  268.                  iRetval = DelPrinter(strServer, strPrinter, strUser, strPassword)
  269.             
  270.             case kActionDelAll
  271.                  iRetval = DelAllPrinters(kActionDelAll, strServer, strUser, strPassword)
  272.             
  273.             case kActionDelAllCon
  274.                  iRetval = DelAllPrinters(kActionDelAllCon, strServer, strUser, strPassword)
  275.                  
  276.             case kActionDelAllLocal
  277.                  iRetval = DelAllPrinters(kActionDelAllLocal, strServer, strUser, strPassword)
  278.  
  279.             case kActionList
  280.                  iRetval = ListPrinters(strServer, strUser, strPassword)
  281.                  
  282.             case kActionGetDefaultPrinter
  283.                  iRetval = GetDefaultPrinter(strUser, strPassword)
  284.  
  285.             case kActionSetDefaultPrinter
  286.                  iRetval = SetDefaultPrinter(strPrinter, strUser, strPassword)
  287.  
  288.             case kActionUnknown
  289.                  Usage(true)
  290.                  exit sub
  291.  
  292.             case else
  293.                  Usage(true)
  294.                  exit sub
  295.  
  296.         end select
  297.  
  298.     end if
  299.  
  300. end sub
  301.  
  302. '
  303. ' Add a printer with minimum settings. Use prncnfg.vbs to
  304. ' set the complete configuration of a printer
  305. '
  306. function AddPrinter(strServer, strPrinter, strDriver, strPort, strUser, strPassword)
  307.     
  308.     on error resume next    
  309.  
  310.     DebugPrint kDebugTrace, L_Text_Dbg_Msg01_Text
  311.     DebugPrint kDebugTrace, L_Text_Msg_Printer01_Text & L_Space_Text & strServer
  312.     DebugPrint kDebugTrace, L_Text_Msg_Printer02_Text & L_Space_Text & strPrinter
  313.     DebugPrint kDebugTrace, L_Text_Msg_Printer04_Text & L_Space_Text & strDriver
  314.     DebugPrint kDebugTrace, L_Text_Msg_Printer05_Text & L_Space_Text & strPort
  315.     
  316.     dim oPrinter
  317.     dim oService
  318.     dim iRetval
  319.     
  320.     if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then
  321.         
  322.         set oPrinter = oService.Get("Win32_Printer").SpawnInstance_
  323.  
  324.     else
  325.     
  326.         AddPrinter = kErrorFailure
  327.         
  328.         exit function        
  329.     
  330.     end if    
  331.     
  332.     oPrinter.DriverName = strDriver
  333.     oPrinter.PortName   = strPort
  334.     oPrinter.DeviceID   = strPrinter
  335.  
  336.     oPrinter.Put_(kFlagCreateOnly)
  337.     
  338.     if Err.Number = kErrorSuccess then
  339.  
  340.         wscript.echo L_Text_Msg_General01_Text & L_Space_Text & strPrinter
  341.         
  342.         iRetval = kErrorSuccess
  343.  
  344.     else
  345.  
  346.         wscript.echo L_Text_Msg_General02_Text & L_Space_Text & strPrinter & L_Space_Text & L_Error_Text _ 
  347.                      & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  348.         
  349.         '
  350.         ' Try getting extended error information
  351.         '         
  352.         call LastError()
  353.                      
  354.         iRetval = kErrorFailure                     
  355.                                       
  356.     end if
  357.     
  358.     AddPrinter = iRetval
  359.  
  360. end function
  361.  
  362. '
  363. ' Add a printer connection
  364. '
  365. function AddPrinterConnection(strPrinter, strUser, strPassword)
  366.  
  367.     on error resume next
  368.  
  369.     DebugPrint kDebugTrace, L_Text_Dbg_Msg02_Text
  370.     
  371.     dim oPrinter
  372.     dim oService
  373.     dim iRetval
  374.     dim uResult
  375.     
  376.     '
  377.     ' Initialize return value
  378.     '
  379.     iRetval = kErrorFailure
  380.  
  381.     '
  382.     ' We connect to the local server
  383.     '                
  384.     if WmiConnect("", kNameSpace, strUser, strPassword, oService) then
  385.         
  386.         set oPrinter = oService.Get("Win32_Printer")
  387.     
  388.     else
  389.     
  390.         AddPrinterConnection = kErrorFailure
  391.         
  392.         exit function        
  393.     
  394.     end if
  395.     
  396.     '
  397.     ' Check if Get was successful
  398.     '
  399.     if Err.Number = kErrorSuccess then
  400.         
  401.         '
  402.         ' The Err object indicates whether the WMI provider reached the execution
  403.         ' of the function that adds a printer connection. The uResult is the Win32 
  404.         ' error code returned by the static method that adds a printer connection
  405.         '
  406.         uResult = oPrinter.AddPrinterConnection(strPrinter)
  407.     
  408.         if Err.Number = kErrorSuccess then
  409.  
  410.             if uResult = kErrorSuccess then 
  411.             
  412.                 wscript.echo L_Text_Msg_General03_Text & L_Space_Text & strPrinter 
  413.             
  414.                 iRetval = kErrorSuccess
  415.                 
  416.             else 
  417.             
  418.                 wscript.echo L_Text_Msg_General04_Text & L_Space_Text & L_Text_Error_General03_Text _ 
  419.                              & L_Space_text & uResult
  420.             
  421.             end if    
  422.  
  423.         else
  424.          
  425.             wscript.echo L_Text_Msg_General04_Text & L_Space_Text & strPrinter & L_Space_Text _
  426.                          & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
  427.                          & Err.Description
  428.                     
  429.         end if
  430.         
  431.     else
  432.     
  433.         wscript.echo L_Text_Msg_General04_Text & L_Space_Text & strPrinter & L_Space_Text _
  434.                      & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
  435.                      & Err.Description
  436.     
  437.     end if    
  438.     
  439.     AddPrinterConnection = iRetval
  440.  
  441. end function
  442.  
  443. '
  444. ' Delete a printer or a printer connection
  445. '
  446. function DelPrinter(strServer, strPrinter, strUser, strPassword)
  447.  
  448.     on error resume next
  449.  
  450.     DebugPrint kDebugTrace, L_Text_Dbg_Msg03_Text
  451.     DebugPrint kDebugTrace, L_Text_Msg_Printer01_Text & L_Space_Text & strServer
  452.     DebugPrint kDebugTrace, L_Text_Msg_Printer02_Text & L_Space_Text & strPrinter
  453.     
  454.     dim oService
  455.     dim oPrinter
  456.     dim iRetval
  457.     
  458.     iRetval = kErrorFailure
  459.     
  460.     if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then
  461.         
  462.         set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")
  463.  
  464.     else
  465.     
  466.         DelPrinter = kErrorFailure
  467.         
  468.         exit function        
  469.     
  470.     end if        
  471.  
  472.     '
  473.     ' Check if Get was successful
  474.     '
  475.     if Err.Number = kErrorSuccess then
  476.         
  477.         oPrinter.Delete_
  478.     
  479.         if Err.Number = kErrorSuccess then
  480.  
  481.             wscript.echo L_Text_Msg_General05_Text & L_Space_Text & strPrinter
  482.             
  483.             iRetval = kErrorSuccess
  484.             
  485.         else
  486.          
  487.             wscript.echo L_Text_Msg_General06_Text & L_Space_Text & strPrinter & L_Space_Text _
  488.                          & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _
  489.                          & L_Space_Text & Err.Description
  490.             
  491.             '
  492.             ' Try getting extended error information
  493.             '             
  494.             call LastError()            
  495.                     
  496.         end if
  497.         
  498.     else
  499.     
  500.         wscript.echo L_Text_Msg_General06_Text & L_Space_Text & strPrinter & L_Space_Text _
  501.                      & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _
  502.                      & L_Space_Text & Err.Description
  503.                       
  504.         '
  505.         ' Try getting extended error information
  506.         '                       
  507.         call LastError()              
  508.     
  509.     end if
  510.     
  511.     DelPrinter = iRetval
  512.  
  513. end function
  514.  
  515. '
  516. ' Delete all local printers and connections on a machine
  517. '
  518. function DelAllPrinters(kAction, strServer, strUser, strPassword)
  519.  
  520.     on error resume next 
  521.     
  522.     DebugPrint kDebugTrace, L_Text_Dbg_Msg04_Text
  523.  
  524.     dim Printers
  525.     dim oPrinter
  526.     dim oService
  527.     dim iResult
  528.     dim iTotal
  529.     dim iTotalDeleted
  530.     dim strPrinterName
  531.     dim bDelete
  532.     dim bConnection
  533.     dim strTemp
  534.     
  535.     if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then
  536.         
  537.         set Printers = oService.InstancesOf("Win32_Printer")
  538.     
  539.     else
  540.     
  541.         DelAllPrinters = kErrorFailure
  542.         
  543.         exit function        
  544.     
  545.     end if
  546.     
  547.     if Err.Number <> kErrorSuccess then         
  548.     
  549.         wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  550.                      & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  551.  
  552.         DelAllPrinters = kErrorFailure
  553.             
  554.         exit function
  555.         
  556.     end if
  557.     
  558.     iTotal = 0
  559.     iTotalDeleted = 0   
  560.         
  561.     for each oPrinter in Printers
  562.         
  563.         strPrinterName = oPrinter.DeviceID
  564.         
  565.         bConnection = oPrinter.Network
  566.         
  567.         if kAction = kActionDelAll then
  568.             
  569.             bDelete = 1
  570.             
  571.             iTotal = iTotal + 1 
  572.             
  573.         elseif kAction = kActionDelAllCon and bConnection then
  574.         
  575.             bDelete = 1
  576.             
  577.             iTotal = iTotal + 1 
  578.             
  579.         elseif kAction = kActionDelAllLocal and not bConnection then
  580.         
  581.             bDelete = 1   
  582.             
  583.             iTotal = iTotal + 1 
  584.             
  585.         else
  586.         
  587.             bDelete = 0    
  588.                
  589.         end if
  590.  
  591.         if bDelete = 1 then
  592.         
  593.             if bConnection then
  594.             
  595.                 strTemp = L_Space_Text & L_Connection_Text & L_Space_Text
  596.                 
  597.             else
  598.             
  599.                 strTemp = L_Space_Text
  600.                
  601.             end if       
  602.         
  603.             '
  604.             ' Delete printer instance
  605.             '
  606.             oPrinter.Delete_
  607.             
  608.             if Err.Number = kErrorSuccess then
  609.    
  610.                 wscript.echo L_Text_Msg_General05_Text & strTemp & oPrinter.DeviceID
  611.                 
  612.                 iTotalDeleted = iTotalDeleted + 1   
  613.    
  614.             else
  615.          
  616.                 wscript.echo L_Text_Msg_General06_Text & strTemp & strPrinterName _
  617.                              & L_Space_Text & L_Error_Text & L_Space_Text & L_Hex_Text _
  618.                              & hex(Err.Number) & L_Space_Text & Err.Description
  619.             
  620.                 '
  621.                 ' Try getting extended error information
  622.                 '
  623.                 call LastError()
  624.                
  625.                 '
  626.                 ' Continue deleting the rest of the printers despite this error
  627.                 '
  628.                 Err.Clear
  629.                
  630.             end if      
  631.         
  632.         end if                
  633.          
  634.     next
  635.  
  636.     wscript.echo L_Empty_Text
  637.     
  638.     if kAction = kActionDelAll then
  639.             
  640.         wscript.echo L_Text_Msg_General09_Text & L_Space_Text & iTotal 
  641.         wscript.echo L_Text_Msg_General10_Text & L_Space_Text & iTotalDeleted
  642.             
  643.     elseif kAction = kActionDelAllCon then
  644.         
  645.         wscript.echo L_Text_Msg_General16_Text & L_Space_Text & iTotal 
  646.         wscript.echo L_Text_Msg_General17_Text & L_Space_Text & iTotalDeleted
  647.            
  648.     elseif kAction = kActionDelAllLocal then
  649.     
  650.         wscript.echo L_Text_Msg_General18_Text & L_Space_Text & iTotal 
  651.         wscript.echo L_Text_Msg_General19_Text & L_Space_Text & iTotalDeleted
  652.         
  653.     else
  654.         
  655.     end if
  656.                                  
  657.     DelAllPrinters = kErrorSuccess
  658.  
  659. end function
  660.  
  661. '
  662. ' List the printers
  663. '
  664. function ListPrinters(strServer, strUser, strPassword)
  665.  
  666.     on error resume next
  667.     
  668.     DebugPrint kDebugTrace, L_Text_Dbg_Msg05_Text
  669.  
  670.     dim Printers
  671.     dim oService
  672.     dim oPrinter
  673.     dim iTotal
  674.  
  675.     if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then
  676.         
  677.         set Printers = oService.InstancesOf("Win32_Printer")
  678.     
  679.     else
  680.     
  681.         ListPrinters = kErrorFailure
  682.         
  683.         exit function        
  684.     
  685.     end if
  686.     
  687.     if Err.Number <> kErrorSuccess then         
  688.     
  689.         wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  690.                      & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  691.  
  692.         ListPrinters = kErrorFailure
  693.             
  694.         exit function
  695.         
  696.     end if    
  697.              
  698.     iTotal = 0
  699.                    
  700.     for each oPrinter in Printers 
  701.     
  702.         iTotal = iTotal + 1                       
  703.  
  704.         wscript.echo L_Empty_Text
  705.         wscript.echo L_Text_Msg_Printer01_Text & L_Space_Text & strServer
  706.         wscript.echo L_Text_Msg_Printer02_Text & L_Space_Text & oPrinter.DeviceID
  707.         wscript.echo L_Text_Msg_Printer03_Text & L_Space_Text & oPrinter.ShareName
  708.         wscript.echo L_Text_Msg_Printer04_Text & L_Space_Text & oPrinter.DriverName
  709.         wscript.echo L_Text_Msg_Printer05_Text & L_Space_Text & oPrinter.PortName
  710.         wscript.echo L_Text_Msg_Printer06_Text & L_Space_Text & oPrinter.Comment
  711.         wscript.echo L_Text_Msg_Printer07_Text & L_Space_Text & oPrinter.Location
  712.         wscript.echo L_Text_Msg_Printer08_Text & L_Space_Text & oPrinter.SepFile
  713.         wscript.echo L_Text_Msg_Printer09_Text & L_Space_Text & oPrinter.PrintProcessor
  714.         wscript.echo L_Text_Msg_Printer10_Text & L_Space_Text & oPrinter.PrintJobDataType
  715.         wscript.echo L_Text_Msg_Printer11_Text & L_Space_Text & oPrinter.Parameters
  716.         wscript.echo L_Text_Msg_Printer12_Text & L_Space_Text & CSTR(oPrinter.Attributes)
  717.         wscript.echo L_Text_Msg_Printer13_Text & L_Space_Text & CSTR(oPrinter.Priority)
  718.         wscript.echo L_Text_Msg_Printer14_Text & L_Space_Text & CStr(oPrinter.DefaultPriority)
  719.  
  720.         if CStr(oPrinter.StartTime) <> "" and CStr(oPrinter.UntilTime) <> "" then
  721.  
  722.             wscript.echo L_Text_Msg_Printer15_Text & L_Space_Text & Mid(Mid(CStr(oPrinter.StartTime), 9, 4), 1, 2) & "h" & Mid(Mid(CStr(oPrinter.StartTime), 9, 4), 3, 2) 
  723.             wscript.echo L_Text_Msg_Printer16_Text & L_Space_Text & Mid(Mid(CStr(oPrinter.UntilTime), 9, 4), 1, 2) & "h" & Mid(Mid(CStr(oPrinter.UntilTime), 9, 4), 3, 2) 
  724.  
  725.         end if
  726.  
  727.         wscript.echo L_Text_Msg_Printer17_Text & L_Space_Text & CStr(oPrinter.Jobs)
  728.         wscript.echo L_Text_Msg_Printer18_Text & L_Space_Text & CStr(oPrinter.AveragePagesPerMinute)
  729.         wscript.echo L_Text_Msg_Printer19_Text & L_Space_Text & PrnStatusToString(oPrinter.PrinterStatus)
  730.         wscript.echo L_Text_Msg_Printer20_Text & L_Space_Text & ExtPrnStatusToString(oPrinter.ExtendedPrinterStatus) 
  731.         wscript.echo L_Text_Msg_Printer21_Text & L_Space_Text & DetectedErrorStateToString(oPrinter.DetectedErrorState)
  732.         wscript.echo L_Text_Msg_Printer22_Text & L_Space_Text & ExtDetectedErrorStateToString(oPrinter.ExtendedDetectedErrorState)
  733.             
  734.         Err.Clear
  735.         
  736.     next
  737.  
  738.     wscript.echo L_Empty_Text
  739.     wscript.echo L_Text_Msg_General09_Text & L_Space_Text & iTotal 
  740.     
  741.     ListPrinters = kErrorSuccess
  742.  
  743. end function
  744.  
  745. '
  746. ' Get the default printer
  747. '
  748. function GetDefaultPrinter(strUser, strPassword)
  749.  
  750.     on error resume next
  751.     
  752.     DebugPrint kDebugTrace, L_Text_Dbg_Msg06_Text
  753.  
  754.     dim oService
  755.     dim oPrinter
  756.     dim iRetval
  757.     dim oEnum
  758.     
  759.     iRetval = kErrorFailure
  760.     
  761.     '
  762.     ' We connect to the local server
  763.     '                
  764.     if WmiConnect("", kNameSpace, strUser, strPassword, oService) then
  765.         
  766.         set oEnum    = oService.ExecQuery("select DeviceID from Win32_Printer where default=true")
  767.     
  768.     else
  769.     
  770.         SetDefaultPrinter = kErrorFailure
  771.         
  772.         exit function        
  773.     
  774.     end if
  775.     
  776.     if Err.Number = kErrorSuccess then
  777.     
  778.          for each oPrinter in oEnum
  779.          
  780.             wscript.echo L_Text_Msg_General12_Text & L_Space_Text & oPrinter.DeviceID       
  781.                 
  782.          next
  783.          
  784.          iRetval = kErrorSuccess
  785.          
  786.     else
  787.     
  788.         wscript.echo L_Text_Msg_General13_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  789.                      & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  790.          
  791.     end if     
  792.  
  793.     GetDefaultPrinter = iRetval
  794.  
  795. end function
  796.  
  797. '
  798. ' Set the default printer
  799. '
  800. function SetDefaultPrinter(strPrinter, strUser, strPassword)
  801.  
  802.     'on error resume next
  803.  
  804.     DebugPrint kDebugTrace, L_Text_Dbg_Msg07_Text
  805.     
  806.     dim oService
  807.     dim oPrinter
  808.     dim iRetval
  809.     dim uResult
  810.     
  811.     iRetval = kErrorFailure
  812.     
  813.     '
  814.     ' We connect to the local server
  815.     '                
  816.     if WmiConnect("", kNameSpace, strUser, strPassword, oService) then
  817.         
  818.         set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")
  819.     
  820.     else
  821.     
  822.         SetDefaultPrinter = kErrorFailure
  823.         
  824.         exit function        
  825.     
  826.     end if
  827.     
  828.     '
  829.     ' Check if Get was successful
  830.     '
  831.     if Err.Number = kErrorSuccess then
  832.         
  833.         '
  834.         ' The Err object indicates whether the WMI provider reached the execution
  835.         ' of the function that sets the default printer. The uResult is the Win32 
  836.         ' error code of the spooler function that sets the default printer
  837.         '
  838.         uResult = oPrinter.SetDefaultPrinter
  839.     
  840.         if Err.Number = kErrorSuccess then
  841.  
  842.             if uResult = kErrorSuccess then 
  843.             
  844.                 wscript.echo L_Text_Msg_General15_Text & L_Space_Text & strPrinter
  845.             
  846.                 iRetval = kErrorSuccess
  847.             
  848.             else
  849.             
  850.                 wscript.echo L_Text_Msg_General14_Text & L_Space_Text _
  851.                              & L_Text_Error_General03_Text& L_Space_Text & uResult
  852.             
  853.             end if    
  854.             
  855.         else
  856.          
  857.             wscript.echo L_Text_Msg_General14_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  858.                          & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  859.                          
  860.         end if
  861.         
  862.     else
  863.     
  864.         wscript.echo L_Text_Msg_General14_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  865.                      & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
  866.                      
  867.         '
  868.         ' Try getting extended error information
  869.         '              
  870.         call LastError()              
  871.     
  872.     end if
  873.     
  874.     SetDefaultPrinter = iRetval
  875.  
  876. end function
  877.  
  878. '
  879. ' Converts the printer status to a string
  880. '
  881. function PrnStatusToString(Status)
  882.  
  883.     dim str
  884.  
  885.     str = L_Empty_Text
  886.  
  887.     select case Status
  888.  
  889.         case 1
  890.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  891.             
  892.         case 2    
  893.             str = str + L_Text_Msg_Status02_Text + L_Space_Text
  894.             
  895.         case 3
  896.             str = str + L_Text_Msg_Status03_Text + L_Space_Text
  897.             
  898.         case 4
  899.             str = str + L_Text_Msg_Status04_Text + L_Space_Text
  900.             
  901.         case 5
  902.             str = str + L_Text_Msg_Status05_Text + L_Space_Text
  903.             
  904.         case 6
  905.             str = str + L_Text_Msg_Status06_Text + L_Space_Text
  906.             
  907.         case 7
  908.             str = str + L_Text_Msg_Status07_Text + L_Space_Text
  909.  
  910.     end select
  911.  
  912.     PrnStatusToString = str
  913.  
  914. end function
  915.  
  916. '
  917. ' Converts the extended printer status to a string
  918. '
  919. function ExtPrnStatusToString(Status)
  920.  
  921.     dim str
  922.  
  923.     str = L_Empty_Text
  924.  
  925.     select case Status
  926.  
  927.         case 1
  928.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  929.             
  930.         case 2    
  931.             str = str + L_Text_Msg_Status02_Text + L_Space_Text
  932.             
  933.         case 3
  934.             str = str + L_Text_Msg_Status03_Text + L_Space_Text
  935.             
  936.         case 4
  937.             str = str + L_Text_Msg_Status04_Text + L_Space_Text    
  938.             
  939.         case 5
  940.             str = str + L_Text_Msg_Status05_Text + L_Space_Text
  941.             
  942.         case 6
  943.             str = str + L_Text_Msg_Status06_Text + L_Space_Text
  944.             
  945.         case 7
  946.             str = str + L_Text_Msg_Status07_Text + L_Space_Text
  947.             
  948.         case 8
  949.             str = str + L_Text_Msg_Status08_Text + L_Space_Text    
  950.             
  951.         case 9
  952.             str = str + L_Text_Msg_Status09_Text + L_Space_Text
  953.             
  954.         case 10
  955.             str = str + L_Text_Msg_Status10_Text + L_Space_Text
  956.        
  957.         case 11
  958.             str = str + L_Text_Msg_Status11_Text + L_Space_Text
  959.                            
  960.         case 12
  961.             str = str + L_Text_Msg_Status12_Text + L_Space_Text
  962.      
  963.         case 13
  964.             str = str + L_Text_Msg_Status13_Text + L_Space_Text
  965.  
  966.         case 14
  967.             str = str + L_Text_Msg_Status14_Text + L_Space_Text
  968.             
  969.         case 15
  970.             str = str + L_Text_Msg_Status15_Text + L_Space_Text
  971.  
  972.         case 16
  973.             str = str + L_Text_Msg_Status16_Text + L_Space_Text    
  974.             
  975.         case 17
  976.             str = str + L_Text_Msg_Status17_Text + L_Space_Text
  977.             
  978.         case 18
  979.             str = str + L_Text_Msg_Status18_Text + L_Space_Text        
  980.  
  981.     end select
  982.  
  983.     ExtPrnStatusToString = str
  984.  
  985. end function
  986.  
  987. '
  988. ' Converts the detected error state to a string
  989. '
  990. function DetectedErrorStateToString(Status)
  991.  
  992.     dim str
  993.  
  994.     str = L_Empty_Text
  995.  
  996.     select case Status
  997.  
  998.         case 0
  999.             str = str + L_Text_Msg_Status02_Text + L_Space_Text
  1000.             
  1001.         case 1    
  1002.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  1003.             
  1004.         case 2
  1005.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  1006.             
  1007.         case 3
  1008.             str = str + L_Text_Msg_Status20_Text + L_Space_Text
  1009.             
  1010.         case 4
  1011.             str = str + L_Text_Msg_Status21_Text + L_Space_Text
  1012.             
  1013.         case 5
  1014.             str = str + L_Text_Msg_Status22_Text + L_Space_Text
  1015.             
  1016.         case 6
  1017.             str = str + L_Text_Msg_Status23_Text + L_Space_Text
  1018.             
  1019.         case 7
  1020.             str = str + L_Text_Msg_Status24_Text + L_Space_Text    
  1021.             
  1022.         case 8
  1023.             str = str + L_Text_Msg_Status25_Text + L_Space_Text
  1024.             
  1025.         case 9
  1026.             str = str + L_Text_Msg_Status07_Text + L_Space_Text        
  1027.        
  1028.         case 10
  1029.             str = str + L_Text_Msg_Status26_Text + L_Space_Text        
  1030.                            
  1031.         case 11
  1032.             str = str + L_Text_Msg_Status27_Text + L_Space_Text        
  1033.         
  1034.     end select
  1035.  
  1036.     DetectedErrorStateToString = str
  1037.  
  1038. end function      
  1039.  
  1040. '
  1041. ' Converts the extended detected error state to a string
  1042. '
  1043. function ExtDetectedErrorStateToString(Status)
  1044.  
  1045.     dim str
  1046.  
  1047.     str = L_Empty_Text
  1048.  
  1049.     select case Status
  1050.  
  1051.         case 0
  1052.             str = str + L_Text_Msg_Status02_Text + L_Space_Text
  1053.             
  1054.         case 1    
  1055.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  1056.             
  1057.         case 2
  1058.             str = str + L_Text_Msg_Status01_Text + L_Space_Text
  1059.             
  1060.         case 3
  1061.             str = str + L_Text_Msg_Status20_Text + L_Space_Text
  1062.             
  1063.         case 4
  1064.             str = str + L_Text_Msg_Status21_Text + L_Space_Text
  1065.             
  1066.         case 5
  1067.             str = str + L_Text_Msg_Status22_Text + L_Space_Text
  1068.             
  1069.         case 6
  1070.             str = str + L_Text_Msg_Status23_Text + L_Space_Text
  1071.             
  1072.         case 7
  1073.             str = str + L_Text_Msg_Status24_Text + L_Space_Text    
  1074.             
  1075.         case 8
  1076.             str = str + L_Text_Msg_Status25_Text + L_Space_Text
  1077.             
  1078.         case 9
  1079.             str = str + L_Text_Msg_Status07_Text + L_Space_Text        
  1080.        
  1081.         case 10
  1082.             str = str + L_Text_Msg_Status26_Text + L_Space_Text        
  1083.                            
  1084.         case 11
  1085.             str = str + L_Text_Msg_Status27_Text + L_Space_Text
  1086.             
  1087.         case 12
  1088.             str = str + L_Text_Msg_Status28_Text + L_Space_Text
  1089.             
  1090.         case 13
  1091.             str = str + L_Text_Msg_Status29_Text + L_Space_Text
  1092.                 
  1093.         case 14
  1094.             str = str + L_Text_Msg_Status30_Text + L_Space_Text
  1095.             
  1096.         case 15
  1097.             str = str + L_Text_Msg_Status31_Text + L_Space_Text
  1098.             
  1099.         case 16
  1100.             str = str + L_Text_Msg_Status32_Text + L_Space_Text
  1101.         
  1102.     end select
  1103.  
  1104.     ExtDetectedErrorStateToString = str
  1105.  
  1106. end function
  1107.  
  1108. '
  1109. ' Debug display helper function
  1110. '
  1111. sub DebugPrint(uFlags, strString)
  1112.  
  1113.     if gDebugFlag = true then
  1114.  
  1115.         if uFlags = kDebugTrace then
  1116.  
  1117.             wscript.echo L_Debug_Text & L_Space_Text & strString
  1118.  
  1119.         end if
  1120.  
  1121.         if uFlags = kDebugError then
  1122.  
  1123.             if Err <> 0 then
  1124.  
  1125.                 wscript.echo L_Debug_Text & L_Space_Text & strString & L_Space_Text _
  1126.                              & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _
  1127.                              & L_Space_Text & Err.Description
  1128.  
  1129.             end if
  1130.  
  1131.         end if
  1132.  
  1133.     end if
  1134.  
  1135. end sub
  1136.  
  1137. '
  1138. ' Parse the command line into its components
  1139. '
  1140. function ParseCommandLine(iAction, strServer, strPrinter, strDriver, strPort, strUser, strPassword)
  1141.  
  1142.     on error resume next    
  1143.  
  1144.     DebugPrint kDebugTrace, L_Text_Dbg_Msg08_Text
  1145.  
  1146.     dim oArgs
  1147.     dim iIndex
  1148.  
  1149.     iAction = kActionUnknown
  1150.     iIndex  = 0
  1151.  
  1152.     set oArgs = wscript.Arguments
  1153.  
  1154.     while iIndex < oArgs.Count
  1155.  
  1156.         select case oArgs(iIndex)
  1157.  
  1158.             case "-a"
  1159.                 iAction = kActionAdd
  1160.  
  1161.             case "-ac"
  1162.                 iAction = kActionAddConn
  1163.             
  1164.             case "-d"
  1165.                 iAction = kActionDel
  1166.  
  1167.             case "-x"
  1168.                 iAction = kActionDelAll
  1169.                 
  1170.             case "-xc"    
  1171.                 iAction = kActionDelAllCon
  1172.                 
  1173.             case "-xo"    
  1174.                 iAction = kActionDelAllLocal
  1175.             
  1176.             case "-l"
  1177.                 iAction = kActionList
  1178.                 
  1179.             case "-g"
  1180.                 iAction = kActionGetDefaultPrinter
  1181.  
  1182.             case "-t"
  1183.                 iAction = kActionSetDefaultPrinter
  1184.  
  1185.             case "-s"
  1186.                 iIndex = iIndex + 1
  1187.                 strServer = RemoveBackslashes(oArgs(iIndex))
  1188.  
  1189.             case "-p"
  1190.                 iIndex = iIndex + 1
  1191.                 strPrinter = oArgs(iIndex)
  1192.             
  1193.             case "-m"
  1194.                 iIndex = iIndex + 1
  1195.                 strDriver = oArgs(iIndex)
  1196.                 
  1197.             case "-u"
  1198.                 iIndex = iIndex + 1
  1199.                 strUser = oArgs(iIndex)
  1200.                 
  1201.             case "-w"
  1202.                 iIndex = iIndex + 1
  1203.                 strPassword = oArgs(iIndex)        
  1204.  
  1205.             case "-r"
  1206.                 iIndex = iIndex + 1
  1207.                 strPort = oArgs(iIndex)
  1208.             
  1209.             case "-?"
  1210.                 Usage(true)
  1211.                 exit function
  1212.  
  1213.             case else
  1214.                 Usage(true)
  1215.                 exit function
  1216.  
  1217.         end select
  1218.  
  1219.         iIndex = iIndex + 1
  1220.  
  1221.     wend    
  1222.  
  1223.     if Err = kErrorSuccess then
  1224.  
  1225.         ParseCommandLine = kErrorSuccess
  1226.  
  1227.     else
  1228.     
  1229.         wscript.echo L_Text_Error_General02_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  1230.                      & L_Hex_Text & hex(Err.Number) & L_Space_text & Err.Description
  1231.         
  1232.         ParseCommandLine = kErrorFailure        
  1233.  
  1234.     end if    
  1235.     
  1236. end  function
  1237.  
  1238. '
  1239. ' Display command usage.
  1240. '
  1241. sub Usage(bExit)
  1242.  
  1243.     wscript.echo L_Help_Help_General01_Text
  1244.     wscript.echo L_Help_Help_General02_Text
  1245.     wscript.echo L_Help_Help_General03_Text
  1246.     wscript.echo L_Help_Help_General04_Text
  1247.     wscript.echo L_Help_Help_General05_Text
  1248.     wscript.echo L_Help_Help_General06_Text
  1249.     wscript.echo L_Help_Help_General07_Text
  1250.     wscript.echo L_Help_Help_General08_Text
  1251.     wscript.echo L_Help_Help_General09_Text
  1252.     wscript.echo L_Help_Help_General10_Text
  1253.     wscript.echo L_Help_Help_General11_Text
  1254.     wscript.echo L_Help_Help_General12_Text
  1255.     wscript.echo L_Help_Help_General13_Text
  1256.     wscript.echo L_Help_Help_General14_Text
  1257.     wscript.echo L_Help_Help_General15_Text    
  1258.     wscript.echo L_Help_Help_General16_Text 
  1259.     wscript.echo L_Help_Help_General17_Text
  1260.     wscript.echo L_Help_Help_General18_Text
  1261.     wscript.echo L_Help_Help_General19_Text
  1262.     wscript.echo L_Empty_Text
  1263.     wscript.echo L_Help_Help_General20_Text
  1264.     wscript.echo L_Help_Help_General21_Text
  1265.     wscript.echo L_Help_Help_General22_Text
  1266.     wscript.echo L_Help_Help_General23_Text
  1267.     wscript.echo L_Help_Help_General24_Text
  1268.     wscript.echo L_Help_Help_General25_Text
  1269.     wscript.echo L_Help_Help_General26_Text
  1270.     wscript.echo L_Help_Help_General27_Text
  1271.     wscript.echo L_Help_Help_General28_Text
  1272.     wscript.echo L_Help_Help_General29_Text
  1273.  
  1274.     if bExit then
  1275.     
  1276.         wscript.quit(1)
  1277.         
  1278.     end if
  1279.  
  1280. end sub
  1281.  
  1282. '
  1283. ' Determines which program is being used to run this script. 
  1284. ' Returns true if the script host is cscript.exe
  1285. '
  1286. function IsHostCscript()
  1287.  
  1288.     on error resume next
  1289.     
  1290.     dim strFullName 
  1291.     dim strCommand 
  1292.     dim i, j 
  1293.     dim bReturn
  1294.     
  1295.     bReturn = false
  1296.     
  1297.     strFullName = WScript.FullName
  1298.     
  1299.     i = InStr(1, strFullName, ".exe", 1)
  1300.     
  1301.     if i <> 0 then
  1302.         
  1303.         j = InStrRev(strFullName, "\", i, 1)
  1304.         
  1305.         if j <> 0 then
  1306.             
  1307.             strCommand = Mid(strFullName, j+1, i-j-1)
  1308.             
  1309.             if LCase(strCommand) = "cscript" then
  1310.             
  1311.                 bReturn = true  
  1312.             
  1313.             end if    
  1314.                 
  1315.         end if
  1316.         
  1317.     end if
  1318.     
  1319.     if Err <> 0 then
  1320.     
  1321.         wscript.echo L_Text_Error_General01_Text & L_Space_Text & L_Error_Text & L_Space_Text _
  1322.                      & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description 
  1323.         
  1324.     end if
  1325.     
  1326.     IsHostCscript = bReturn
  1327.  
  1328. end function
  1329.  
  1330. '
  1331. ' Retrieves extended information about the last error that occurred 
  1332. ' during a WBEM operation. The methods that set an SWbemLastError
  1333. ' object are GetObject, PutInstance, DeleteInstance
  1334. '
  1335. sub LastError()
  1336.  
  1337.     on error resume next
  1338.  
  1339.     dim oError
  1340.  
  1341.     set oError = CreateObject("WbemScripting.SWbemLastError")
  1342.    
  1343.     if Err = kErrorSuccess then
  1344.    
  1345.         wscript.echo L_Operation_Text            & L_Space_Text & oError.Operation
  1346.         wscript.echo L_Provider_Text             & L_Space_Text & oError.ProviderName
  1347.         wscript.echo L_Description_Text          & L_Space_Text & oError.Description
  1348.         wscript.echo L_Text_Error_General03_Text & L_Space_Text & oError.StatusCode
  1349.                 
  1350.     end if                                                             
  1351.                                                              
  1352. end sub
  1353.  
  1354. '
  1355. ' Connects to the WMI service on a server. oService is returned as a service
  1356. ' object (SWbemServices)
  1357. '
  1358. function WmiConnect(strServer, strNameSpace, strUser, strPassword, oService)
  1359.  
  1360.     on error resume next
  1361.  
  1362.     dim oLocator
  1363.     dim bResult
  1364.    
  1365.     oService = null
  1366.    
  1367.     bResult  = false
  1368.    
  1369.     set oLocator = CreateObject("WbemScripting.SWbemLocator")
  1370.  
  1371.     if Err = kErrorSuccess then
  1372.  
  1373.         set oService = oLocator.ConnectServer(strServer, strNameSpace, strUser, strPassword)
  1374.  
  1375.         if Err = kErrorSuccess then
  1376.  
  1377.             bResult = true
  1378.       
  1379.             oService.Security_.impersonationlevel = 3
  1380.  
  1381.             '
  1382.             ' Required to perform administrative tasks on the spooler service
  1383.             '
  1384.             oService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
  1385.           
  1386.             Err.Clear
  1387.       
  1388.         else
  1389.  
  1390.             wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text _
  1391.                          & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
  1392.                          & Err.Description
  1393.             
  1394.         end if
  1395.    
  1396.     else
  1397.    
  1398.         wscript.echo L_Text_Msg_General10_Text & L_Space_Text & L_Error_Text _
  1399.                      & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
  1400.                      & Err.Description
  1401.          
  1402.     end if                                                         
  1403.    
  1404.     WmiConnect = bResult
  1405.             
  1406. end function
  1407.  
  1408. '
  1409. ' Remove leading "\\" from server name
  1410. '
  1411. function RemoveBackslashes(strServer)
  1412.  
  1413.     dim strRet
  1414.     
  1415.     strRet = strServer
  1416.     
  1417.     if Left(strServer, 2) = "\\" and Len(strServer) > 2 then 
  1418.    
  1419.         strRet = Mid(strServer, 3) 
  1420.         
  1421.     end if   
  1422.  
  1423.     RemoveBackslashes = strRet
  1424.  
  1425. end function
  1426.